home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
443_01
/
doc
/
info
/
cncl.info-4
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
GNU Info File
|
1996-01-04
|
46.2 KB
|
1,672 lines
This is Info file cncl.info, produced by Makeinfo-1.63 from the input
file cncl.texi.
This file documents the use of CNCL, the Communication Networks Class
Library.
Copyright (C) 1993-1996, Communication Networks.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into other languages, under the above conditions for modified
versions.
File: cncl.info, Node: CNSimTime, Next: Event Example, Prev: CNEventIterator, Up: Events
CNSimTime -- Simulation Time
============================
SYNOPSIS
--------
`#include <CNCL/SimTime.h>'
TYPE
----
`typedef double CNSimTime'
DESCRIPTION
-----------
`CNSimTime' is a double variable which keeps the current simulation
time.
File: cncl.info, Node: Event Example, Next: CNArray, Prev: CNSimTime, Up: Events
Example of an Event Driven Simulation
=====================================
The following example shows how to program an M/M/1 queuing system
simulation with CNCL events:
// -*- C++ -*-
#include <iostream.h>
#include <CNCL/QueueFIFO.h>
#include <CNCL/EventScheduler.h>
#include <CNCL/FiboG.h>
#include <CNCL/NegExp.h>
#include <CNCL/Moments.h>
#include <CNCL/Job.h>
enum { NJOBS=100000 };
enum { EV_JOB, EV_TIMER_G, EV_TIMER_S }; // Event types for M/M/1 simulation
class Server : public CNEventHandler
{
private:
CNJob *job; // Served job
CNQueueFIFO queue; // CNQueue
CNRandom &rnd_b; // Distribution of service time b
CNMoments t_w, t_b; // Evaluation tau_w, tau_b
enum { ST_WAITING, ST_SERVING };
public:
virtual void event_handler(const CNEvent *ev);
void print_results();
void eval_job(CNJob *job);
Server(CNRandom &rnd) : rnd_b(rnd), job(NIL), t_w("tau_w"), t_b("tau_b")
{
state(ST_WAITING);
}
};
class Generator : public CNEventHandler
{
private:
CNRandom &rnd_a; // Distribution of arrival time a
Server *server; // Connected queue/server
long n;
public:
virtual void event_handler(const CNEvent *ev);
Generator(CNRandom &rnd,Server *serv) : rnd_a(rnd),server(serv),n(0) {}
};
void Generator::event_handler(const CNEvent *ev)
{
if(n == NJOBS)
// Stop simulation
return;
// Incoming event -> generate new Job
send_now(new CNEvent(EV_JOB, server, new CNJob));
// Random delay
send_delay(new CNEvent(EV_TIMER_G), rnd_a());
n++;
}
void Server::event_handler(const CNEvent *ev)
{
switch(state())
{
case ST_SERVING:
switch(ev->type())
{
case EV_JOB:
// Incoming job, put into queue
{
CNJob *job;
job = (CNJob *)ev->object();
job->in = now();
queue.put(job);
}
break;
case EV_TIMER_S:
// Timer event, service time run down
job->out = now();
// Evaluate job
eval_job(job);
delete job;
job = NIL;
// Get new job from queue
if(!queue.empty())
{
job = (CNJob *)queue.get();
job->start = now();
// Random service time
send_delay(new CNEvent(EV_TIMER_S), rnd_b());
state(ST_SERVING);
}
else
state(ST_WAITING);
break;
}
break;
case ST_WAITING:
switch(ev->type())
{
case EV_JOB:
// Incoming job
job = (CNJob *)ev->object();
job->in = now();
job->start = now();
// CNRandom service time
send_delay(new CNEvent(EV_TIMER_S), rnd_b());
state(ST_SERVING);
break;
}
break;
}
}
void Server::eval_job(CNJob *job)
{
t_w.put(job->start - job->in);
t_b.put(job->out - job->in);
}
void Server::print_results()
{
cout << t_w << t_b;
}
main()
{
CNRNG *rng = new CNFiboG;
CNNegExp rnd_a(10, rng);
CNNegExp rnd_b( 5, rng);
Server server(rnd_b);
Generator generator(rnd_a, &server);
CNEventScheduler scheduler;
scheduler.start(new CNEvent(EV_TIMER_G, &generator));
server.print_results();
}
File: cncl.info, Node: Arrays, Next: Object Management, Prev: Events, Up: Top
Array Classes
*************
The class `CNArray' and the derived classes provide arrays of
different data types with array range checking. `CNArrayObject'
manages pointers to `CNObject'. The other classes `CNArray'<type>
manage arrays of standard data types.
The main purpose of these classes is to provide arrays with range
checking, i.e. access to an array element outside the arrays bounds
will terminate the program.
Range checking may be disabled by defining the preprocessor macro
`NO_RANGE_CHECK', e.g. by supplying `-DNO_RANGE_CHECK' on the
compiler's command line.
* Menu:
CNArray Classes
---------------
* CNArray:: Abstract Array Base Class
* CNArrayObject:: Array of Pointer to CNObject
* CNArrayInt:: Array of Integer
* Other CNArray<type>:: Arrays of Other <Type>s
* CNArray2:: Base class for 2-dimensional arrays
* CNArray2Char:: char array class
* Other CNArray2<type>::Other array classes
File: cncl.info, Node: CNArray, Next: CNArrayObject, Prev: Event Example, Up: Arrays
CNArray -- Abstract Array Base Class
====================================
SYNOPSIS
--------
`#include <CNCL/Array.h>'
TYPE
----
`CN_ARRAY'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
* CNArrayObject:: Array of Pointer to CNObject
* CNArrayInt:: Array of Int
* Other CNArray<type>:: Arrays of Other <Type>s
RELATED CLASSES
---------------
DESCRIPTION
-----------
`CNArray' is the base class of the `CNArray'<type> classes. It
defines the common interface.
Constructors:
`CNArray();'
`CNArray(size_t xsize);'
Initializes `CNArray'.
In addition to the member functions required by CNCL, `CNArray'
provides:
`size_t get_size() const;'
`size_t size() const;'
Returns the size of the array.
`void set_size(size_t sz = 0 );'
`virtual void size(size_t sz=0) = 0;'
Sets the size of the array. The `size'-function must be implemented
in the derived classes.
File: cncl.info, Node: CNArrayObject, Next: CNArrayInt, Prev: CNArray, Up: Arrays
CNArrayObject -- Array of Pointer to CNObject
=============================================
SYNOPSIS
--------
`#include <CNCL/ArrayObject.h>'
TYPE
----
`CN_ARRAYOBJECT'
* Menu:
BASE CLASSES
------------
* CNArray:: Abstract Array Base Class
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNArrayInt:: Array of Int
* Other CNArray<type>:: Arrays of Other <Type>s
DESCRIPTION
-----------
`CNArrayObject' manages arrays of pointers to `CNObject'.
Constructors:
`CNArrayObject();'
`CNArrayObject(Param *param);'
`CNArrayObject(size_t sz, CNObjPtr def=0);'
Initializes the array and optionally sets array size to `sz'. All
element pointers are initialized to `NIL' or to `def'.
`CNArrayObject(const CNArrayObject &a);'
Copy constructor.
Destructors:
`~CNArrayObject();'
Deletes the array. The referenced objects are NOT deleted!
In addition to the member functions required by CNCL, `CNArrayObject'
provides:
`typedef CNObject *CNObjPtr;'
`virtual void size(size_t sz = 0 );'
Sets the size of the array.
`void put (int index, CNObjPtr value);'
Puts value into array at indexed location.
`CNObjPtr get (int index) const;'
Returns value of array at indexed location.
`CNObjPtr& operator[] (int index);'
Access to array by `operator []'.
`CNArrayObject &operator= (const CNArrayObject &a);'
Defines the `operator =' for the array to allow copying of arrays.
File: cncl.info, Node: CNArrayInt, Next: Other CNArray<type>, Prev: CNArrayObject, Up: Arrays
CNArrayInt -- Array of Integer
==============================
SYNOPSIS
--------
`#include <CNCL/ArrayInt.h>'
TYPE
----
`CN_ARRAYINT'
* Menu:
BASE CLASSES
------------
* CNArray:: Abstract Array Base Class
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNArrayObject:: Array of Pointer to CNObject
* Other CNArray<type>:: Arrays of Other <Type>s
DESCRIPTION
-----------
`CNArrayInt' manages arrays of integer (the builtin type `int').
`CNArrayInt' is presented here as an example for all `CNArray'<type>
classes. The interface is the same for all classes only considering the
different data types.
Constructors:
`CNArrayInt();'
`CNArrayInt(Param *param);'
`CNArrayInt(size_t sz, int def=0);'
Initializes the array and optionally sets array size to `sz'. All
elements are set to the default value `def'.
`CNArrayInt(const CNArrayInt &a);'
Copy constructor.
Destructors:
`~CNArrayInt();'
Deletes the array.
In addition to the member functions required by CNCL, `CNArrayInt'
provides:
`virtual void size(size_t sz = 0 );'
Sets the size of the array.
`void put (int index, int value);'
Puts value into array at indexed location.
`int get (int index) const;'
Returns value of array at indexed location.
`int& operator[] (int index);'
Access to array by `operator []'.
`CNArrayInt &operator= (const CNArrayInt &a);'
Defines the `operator =' for the array to allow copying of arrays.
File: cncl.info, Node: Other CNArray<type>, Next: CNArray2, Prev: CNArrayInt, Up: Arrays
CNArray<type> -- Arrays of Other <Type>s
========================================
DESCRIPTION
-----------
CNCL currently provides array classes for the data types `char',
`double', `float', `int', `long', and `CNObject *' with the classes
`CNArrayChar', `CNArrayDouble', `CNArrayFloat', `CNArrayInt',
`CNArrayLong', and `CNArrayObject' respectively.
All CNCL compatible objects can be stored in a `CNArrayObject', thus
that there is no need for specialized array types.
Nevertheless it is possible to generate arrays of other data types
with the `CNarray' script.
Usage:
`CNarray' name
The required parameter is the name of the data type. `CNarray'
generates two files ArrayName.h and ArrayName.c with the definition and
implementation of the desired array class.
Please note that name must be a single word, pointers and references
are not allowed, either. If you need an array of pointers or e.g. an
array of `unsigned long', you can use an appropiate typedef:
typedef unsigned long ulong;
typedef Data *DataP;
and then generate an array
CNarray ulong
CNarray DataP
yielding the classes `CNArrayUlong' and `CNArrayDataP'.
File: cncl.info, Node: CNArray2, Next: CNArray2Char, Prev: Other CNArray<type>, Up: Arrays
CNArray2 -- Base class for 2-dimensional arrays
================================================
SYNOPSIS
--------
`#include <CNCL/Array2.h >'
TYPE
----
`CN_ARRAY2'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
* CNArray2Char:: char array class
* Other CNArray2<type>:: Other array classes
RELATED CLASSES
---------------
* CNArray:: Abstract array base class
DESCRIPTION
-----------
`CNArray2' is the base class of the `CNArray2'<type> classes. It
defines the common interface.
Constructors:
`CNArray2();'
`CNArray2(Param *param);'
`CNArray2(size_t r, size_t c);'
Initializes `CNArray2'.The number of rows is r, the number of cols
c.
In addition to the member functions required by CNCL, `CNArray2'
provides:
`size_t get_rows() const;'
`size_t rows() const;'
`size_t get_cols() const;'
`size_t cols() const;'
Returns the number of rows resp. cols.
`virtual void size(size_t r, size_t c) = 0;'
`void set_size(size_t r, size_t c);'
Resizes the array.
File: cncl.info, Node: CNArray2Char, Next: Other CNArray2<type>, Prev: CNArray2, Up: Arrays
CNArray2Char -- char array class
================================
SYNOPSIS
--------
`#include <CNCL/Array2Char.h>'
TYPE
----
`CN_ARRAY2CHAR'
* Menu:
BASE CLASSES
------------
* CNArray2:: Base class for 2-dimensional arrays
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNArray2:: Base class for 2-dimensional arrays
* Other CNArray2<type>::Other array classes
DESCRIPTION
-----------
Constructors:
`CNArray2Char();'
`CNArray2Char(CNParam *param);'
`CNArray2Char(size_t r, size_t c, char def = 0);'
Initializes the `CNArray2Char' and optionally sets the arraysize to
r rows and c cols.
`CNArray2Char(const CNArray2Char &a);'
Copy constructor.
Destructor:
`~CNArray2Char();'
Deletes the array.
In addition to the member functions required by CNCL, `CNArray2Char'
provides:
`virtual void size(size_t r, size_t c);'
Resizes the array to r rows and c cols.
`void put(int r, int c, chr value);'
Writes the character value to position (r, c).
`char get(int r, int c) const;'
Returns the character written on position (r, c).
`CNArrayChar& operator[] (int index);'
Access to array by `operator []'. The row `index' is returned.
`CNArray2Char &operator= (const CNArray2Char &a);'
Defines the `operator =' for the array to allow copying of arrays.
File: cncl.info, Node: Other CNArray2<type>, Next: CNKey, Prev: CNArray2Char, Up: Arrays
CNArray2<type> -- 2 dimensional Arrays of Other <Type>s
=======================================================
DESCRIPTION
-----------
CNCL currently provides 2 dimensional array classes for the data
types `char', `double', `float', `int', `long', and `CNObject *' with
the classes `CNArray2Char', `CNArray2Double', `CNArray2Float',
`CNArray2Int', `CNArray2Long', and `CNArray2Object' respectively. The
description of those classes is similar to `CNArray2Char'.
All CNCL compatible objects can be stored in a `CNArray2Object', thus
that there is no need for specialized array types.
Nevertheless it is possible to generate arrays of other data types
with the `CNarray2' script.
Usage:
`CNarray2' name
The required parameter is the name of the data type. `CNarray2'
generates two files Array2Name.h and Array2Name.c with the definition
and implementation of the desired array class.
Please note that name must be a single word, pointers and references
are not allowed, either. If you need an array of pointers or e.g. an
array of `unsigned long', you can use an appropiate typedef:
typedef unsigned long ulong;
typedef Data *DataP;
and then generate an array
CNarray2 ulong
CNarray2 DataP
yielding the classes `CNArray2Ulong' and `CNArray2DataP'.
File: cncl.info, Node: Object Management, Next: Unix, Prev: Arrays, Up: Top
Object Management
*****************
The classes described in this chapter provide facilities necessary
for object management, as abstract keys, hash tables, and an object
management fronend class.
* Menu:
Hash Tables and Object Management
---------------------------------
* CNKey:: Abstract Base Class for Object Management via Keys
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
* CNHashTable:: Abstract Hash Table Class
* CNHashStatic:: Hash Tables with Static Capacity
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNManager:: Object Management Frontend
File: cncl.info, Node: CNKey, Next: CNKeyString, Prev: Other CNArray2<type>, Up: Object Management
CNKey -- Abstract Base Class for Object Management via Keys
===========================================================
SYNOPSIS
--------
`#include <CNCL/Key.h>'
TYPE
----
`CN_KEY'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
RELATED CLASSES
---------------
* CNHashTable:: Abstract Base Class for Hash Tables
* CNHashStatic:: Hash Tables with Static Capacity
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNManager:: Object Management Frontend
DESCRIPTION
-----------
`CNKey' is an abstract class for managing CNCL compatible objects
via keys. Refer to the desription of the classes derived from `CNKey'
for further information. Objects of this type can be stored in and
retrieved from hash tables.
Constructors:
`CNKey(CNObject *obj = NIL);'
`CNKey(CNParam *param);'
Initializes `CNKey'.
In addition to the member functions required by CNCL, `CNKey'
provides:
`void set_object(CNObject *obj);'
`void set_object(CNObject &obj);'
Stores a CNCL compatible object into the key. Normally, an object
is stored in a key at creation time via the constructor.
`CNObject *get_object() const;'
Gets the object stored in the key. If an object is not available,
`NIL' is returned.
The following virtual functions are to be defined by derived classes:
`virtual unsigned long hash( unsigned long capacity, int par = 0) const = 0;'
Function to evaluate the hash-table value.
`virtual bool compare(CNKey *k) const = 0;'
`virtual bool compare(CNKey &k) const = 0;'
Function to compare two `CNKeys'.
File: cncl.info, Node: CNKeyString, Next: CNKeyInt, Prev: CNKey, Up: Object Management
CNKeyString -- Object Management via String Keys
================================================
SYNOPSIS
--------
`#include <CNCL/KeyString.h>'
TYPE
----
`CN_KEYSTRING'
* Menu:
BASE CLASSES
------------
* CNKey:: Abstract Base Class for Object Management via Keys
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNKeyInt:: Object Management via Integer Keys
* CNHashTable:: Abstract Base Class for Hash Tables
* CNHashStatic:: Hash Tables with Static Capacity
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNManager:: Object Management Frontend
DESCRIPTION
-----------
`CNKeyString' is a class for managing CNCL compatible objects via
`CNString' keys. Objects of this type can be stored in and retrieved
from hash tables.
Constructors:
`CNKeyString(CNStringR key_string, CNObject *obj = NIL);'
`CNKeyString(CNParam *param);'
Initializes `CNKeyString'. The supplied string key is used to
calculate the hash table position. Therefore, the string key must
be unique. Make sure, that the string key is valid during the
whole lifetime of the respective key. Otherwise operations on this
key are unpredictable.
In addition to the member functions required by CNCL, `CNKeyString'
provides:
`CNStringR get_key() const;'
Returns the string key. Unlike the object the string key cannot be
changed.
`virtual unsigned long hash( unsigned long capacity, int par = 0) const;'
Evaluates and returns the hash-table value. `par' is reserved for
future use, any other value than zero will result in an fatal
error.
`virtual bool compare(CNKey *k) const;'
`virtual bool compare(CNKey &k) const;'
Compares two `CNKeys'.
File: cncl.info, Node: CNKeyInt, Next: CNHashTable, Prev: CNKeyString, Up: Object Management
CNKeyInt -- Object Management via Integer Keys
==============================================
SYNOPSIS
--------
`#include <CNCL/KeyInt.h>'
TYPE
----
`CN_KEYINT'
* Menu:
BASE CLASSES
------------
* CNKey:: Abstract Base Class for Object Management via Keys
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNKeyString:: Object Management via String Keys
* CNHashTable:: Abstract Base Class for Hash Tables
* CNHashStatic:: Hash Tables with Static Capacity
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNManager:: Object Management Frontend
DESCRIPTION
-----------
`CNKeyInt' is a class for managing CNCL compatible objects via
integer keys. Objects of this type can be stored in and retrieved from
hash tables.
Constructors:
`CNKeyInt(unsigned long key_int, CNObject *obj = NIL);'
`CNKeyInt(CNParam *param);'
Initializes `CNKeyInt'. The supplied integer key is used to
calculate the hash table position. Therefore, the integer key must
be unique.
In addition to the member functions required by CNCL, `CNKeyInt'
provides:
`unsigned long get_key() const;'
Returns the integer key. Unlike the object the integer key cannot
be changed.
`virtual unsigned long hash( unsigned long capacity, int par = 0) const;'
Evaluates the hash-table value.
`virtual bool compare(CNKey *k) const;'
`virtual bool compare(CNKey &k) const;'
Compares two `CNKeys'.
File: cncl.info, Node: CNHashTable, Next: CNHashStatic, Prev: CNKeyInt, Up: Object Management
CNHashTable -- Abstract Base Class for Hash Tables
==================================================
SYNOPSIS
--------
`#include <CNCL/HashTable.h>'
TYPE
----
`CN_HASHTABLE'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
* CNHashStatic:: Hash Tables with Static Capacity
* CNHashDynamic:: Hash Tables with Dynamic Capacity
RELATED CLASSES
---------------
* CNKey:: Abstract Base Class for Object Management via Keys
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNManager:: Object Management Frontend
DESCRIPTION
-----------
`CNHashTable' is an abstract base class for storing and retrieving
CNCL compatible objects.
Constructors:
`CNHashTable();'
`CNHashTable(CNParam *param);'
Initializes `CNHashTable'.
`CNHashTable' defines the following structs and constants:
`const unsigned long DEFAULT_HASH_TABLE_CAPACITY = 101;'
The default capacity of a hash table. This value is used in
derived classes.
`struct HashEntry { CNKey *he_CNKey; unsigned long he_HashValue; };'
Defines a single entry of the hash table.
`CNHashTable' provides the following virtual functions which have to
be defined in derived classes:
`virtual void store_key(CNKey *k) = 0;'
`virtual void store_key(CNKey &k) = 0;'
Stores a key into the actual hash table (derived from class
`HashTable'). The actual hash table is a homogenous table.
Therefore, only keys of the same type may be stored into one
table. If you nevertheless try to store keys of a different type
into one table, it might be detected by the methods `get_key()' and
`get_object()'. Refer to the description of the derived classes
for further information.
`virtual CNKey *get_key(CNKey *k) const = 0;'
`virtual CNKey *get_key(CNKey &k) const = 0;'
Returns the key which matches the supplied key. If no matching key
was found, `NIL' is returned.
`virtual CNObject *get_object(CNKey *k) const = 0;'
`virtual CNObject *get_object(CNKey &k) const = 0;'
Returns the object of the key which matches the supplied key. If no
matching key was found or if no object has been stored in the key,
`NIL' is returned.
`virtual bool reset() = 0;'
Deletes all entries of the actual hash table and resets it to its
initial state. This method does not free the memory allocated for
the keys stored in the hash table. If the hash table is already
empty, `FALSE' is returned, otherwise `TRUE'.
`virtual bool reset_absolutely() = 0;'
Deletes all entries of the actual hash table and resets it to its
initial state. This method does free the memory allocated for the
keys stored in the hash table. If the hash table is already empty,
`FALSE' is returned, otherwise `TRUE'.
`virtual bool delete_key(Key *k) = 0;'
`virtual bool delete_key(CNKey &k);'
Deletes the key `k' from the actual hash table. This method does
not free the memory allocated for the key stored in the hash
table. If the supplied key does not match any in the table,
`FALSE' is returned, otherwise `TRUE'.
`virtual bool delete_key_absolutely(CNKey *k) = 0;'
`virtual bool delete_key_absolutely(CNKey &k) = 0;'
Deletes the key `k' from the actual hash table. This method does
free the memory allocated for the keys stored in the hash table.
If the supplied key does not match any in the table, `FALSE' is
returned, otherwise `TRUE'.
`virtual bool is_full() const = 0;'
If the actual table's capacity is exhausted, `TRUE' is returned,
otherwise `FALSE'.
`virtual bool is_empty() const = 0;'
If the actual table is empty, `TRUE' is returned, otherwise
`FALSE'.
`virtual unsigned long get_num_entries() const = 0;'
Returns the number of entries of the actual table.
`virtual unsigned long get_capacity() const = 0;'
Returns the capacity of the current table.
File: cncl.info, Node: CNHashStatic, Next: CNHashDynamic, Prev: CNHashTable, Up: Object Management
CNHashStatic -- Hash Tables with Static Capacity
================================================
SYNOPSIS
--------
`#include <CNCL/HashStatic.h>'
TYPE
----
`CN_HASHSTATIC'
* Menu:
BASE CLASSES
------------
* CNHashTable:: Abstract Base Class for Hash Tables
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNKey:: Abstract Base Class for Object Management via Keys
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
DESCRIPTION
-----------
`CNHashStatic' is a class which provides a hash table with static
capacity for storing and retrieving CNCL compatible objects.
Constructors:
`CNHashStatic(unsigned long cap = DEFAULT_HASH_TABLE_CAPACITY);'
`CNHashStatic(CNParam *param);'
Initializes `CNHashStatic'. The hash table's capacity is set to
the value passed to CNHashStatic. The capacity is static,
therefore, you cannot change it during the lifetime of an instance
of this class.
Destructors:
`~CNHashStatic();'
Frees all internally allocated resources.
`CNHashStatic' provides the member functions required by CNCL and
`CNHashTable'. Some member functions defined in `CNHashTable' and
implemented in `CNHashStatic' demand further explanation:
`void store_key(CNKey *k);'
Stores a key into the homogenous hash table. Only keys of the same
type may be stored into the same table. The methods `get_key()' and
`get_object()' should detect it. If you try to store a key into an
already full table, an error message is displayed and the program
is terminated.
`bool delete_key(CNKey *k);'
Deletes the key from the actual hash table which matches the given
key. After having deleted a key from the hash table, the whole
table is rehashed, i.e. the positions of all entries within the
hash table are recalculated and all entries are stored in a new
hash table. This might lead to small time delays when handling
large hash tables. This method does not free the memory allocated
for the keys stored in the hash table. If the supplied key does
not match any in the table, `FALSE' is returned, otherwise `TRUE'.
`bool delete_key_absolutely(CNKey *k);'
Deletes the key from the actual hash table which matches the given
key. After having deleted a key from the hash table, the whole
table is rehashed. This method does free the memory allocated for
the keys stored in the hash table. If the supplied key does not
match any in the table, `FALSE' is returned, otherwise `TRUE'.
The following example shows how to use a `CNHashStatic' object in
order to store and retrieve CNCL compatible objects.
CNHashStatic tab(200);
CNKeyString ks("Test", NIL);
CNObject *obj = &ks;
tab.store_key(new CNKeyString("Jabba", obj));
tab.store_key(new CNKeyString("Dabba"));
tab.store_key(new CNKeyString("Dooo"));
if (tab.get_object(CNKeyString("Jabba")) != obj)
cout << "strange behaviour\n";
else
cout << "found obj\n";
tab.store_key(new CNKeyInt(10, obj)); // error, key of different type
tab.reset_absolutely();
tab.store_key(new CNKeyInt(10, obj)); // okay
File: cncl.info, Node: CNHashDynamic, Next: CNHashIterator, Prev: CNHashStatic, Up: Object Management
CNHashDynamic -- Hash Tables with Dynamic Capacity
==================================================
SYNOPSIS
--------
`#include <CNCL/HashDynamic.h>'
TYPE
----
`CN_HASHDYNAMIC'
* Menu:
BASE CLASSES
------------
* CNHashTable:: Abstract Base Class for Hash Tables
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNHashStatic:: Hash Tables with Static Capacity
* CNHashIterator:: Sequential Iterator for Hash Tables
* CNKey:: Abstract Base Class for Object Management via Keys
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
* CNManager:: Object Management Frontend
DESCRIPTION
-----------
`CNHashDynamic' is a class which provides a hash table with dynamic
capacity for storing and retrieving CNCL compatible objects.
Constructors:
`CNHashDynamic(unsigned long cap = DEFAULT_HASH_TABLE_CAPACITY);'
`CNHashDynamic(CNParam *param);'
Initializes `CNHashDynamic'. The hash table's capacity is set to
the value passed to HashDynamic. The capacity is dynamic, i.e. if
the number of entries exceeds 3/4 of the hash table's capacity, it
is enlarged to a proper value.
Destructors:
`~CNHashDynamic();'
Frees all internally allocated resources.
`CNHashDynamic' provides the member functions required by CNCL and
`CNHashTable'. Some member functions defined in `CNHashTable' and
implemented in `CNHashDynamic' demand further explanation:
`void store_key(CNKey *k);'
Stores a key into the homogenous hash table. Therefore, only keys
of the same type may be stored into the same table. If you
nevertheless try to store keys of different types into one table,
it might be detected by the methods `get_key()' and
`get_object()'. The capacity is dynamic, i.e. if the number of
entries exceeds 3/4 of the hash table's capacity, it is enlarged
to a proper value.
`bool delete_key(CNKey *k);'
Deletes the key from the actual hash table which matches the given
key. After having deleted a key from the hash table, the whole
table is rehashed, i.e. the positions of all entries within the
hash table are recalculated and all entries are stored in a new
hash table. This might lead to small time delays when handling
large hash tables. This method does not free the memory allocated
for the keys stored in the hash table. If the supplied key does
not match any in the table, `FALSE' is returned, otherwise `TRUE'.
`bool delete_key_absolutely(CNKey *k);'
Deletes the key from the actual hash table, which matches the given
key. After having deleted a key from the hash table, the whole
table is rehashed. This method does free the memory allocated for
the keys stored in the hash table. If the supplied key does not
match any in the table, `FALSE' is returned, otherwise `TRUE'.
Refer to `CNHashStatic' for an example as to how to use a
`CNHashDynamic' object in order to store and retrieve CNCL compatible
objects.
File: cncl.info, Node: CNHashIterator, Next: CNManager, Prev: CNHashDynamic, Up: Object Management
CNHashIterator -- Sequential Iterator for Hash Tables
=====================================================
SYNOPSIS
--------
`#include <CNCL/HashIterator.h>'
TYPE
----
`CN_HASHITERATOR'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNHashTable:: Abstract Base Class for Hash Tables
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNHashStatic:: Hash Tables with Static Capacity
* CNKey:: Abstract Base Class for Object Management via Keys
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
* CNManager:: Object Management Frontend
DESCRIPTION
-----------
`CNHashIterator' is an iterator to sequentially traverse a
`CNHashTable' hash table.
Constructors:
`CNHashIterator();'
`CNHashIterator(CNParam *param);'
Initializes `CNHashIterator'.
`CNHashIterator(const CNHashTable *new_hash_table);'
`CNHashIterator(const CNHashTable &new_hash_table);'
Initializes `CNHashIterator' with hash table `new_hash_table'. The
iterator is reset to the first element of the hash table.
In addition to the member functions required by CNCL,
`CNHashIterator' provides:
`void reset(const CNHashTable *new_hash_table);'
`void reset(const CNHashTable &new_hash_table);'
`void reset();'
Resets the iterator to a new hash table `new_hash_table' and/or
sets the iterator to the first element of the hash table.
`CNKey *key()'
`CNKey *get_key()'
Gets the referenced key from the current iterator position. It
returns the key or `NIL', if none is available.
`CNKey *first_key();'
`CNKey *first();'
Sets the iterator to the first element of the hash table. It
returns the referenced key or `NIL', if none is available.
`CNKey *last_key();'
`CNKey *last();'
Sets the iterator to the last element of the hash table. It
returns the referenced key or `NIL', if none is available.
`CNKey *next_key();'
`CNKey *next();'
`CNKey *operator ++();'
`CNKey *operator ++(int);'
Moves the iterator to the next element of the hash table. It
returns the current referenced key (the one BEFORE moving the
iterator) or `NIL', if none is available.
`CNKey *prev_key();'
`CNKey *prev();'
`CNKey *operator --();'
`CNKey *operator --(int);'
Moves the iterator to the previous element of the hash table. It
returns the current referenced key (the one BEFORE moving the
iterator) or `NIL', if none is available.
`CNObject *object()'
`CNObject *get_object()'
Gets the object of the referenced key from the current iterator
position. It returns the object or `NIL', if none is available.
`CNObject *first_object();'
Sets the iterator to the first element of the hash table. It
returns the object of the referenced key or `NIL', if none is
available.
`CNObject *last_object();'
Sets the iterator to the last element of the hash table. It
returns the object of the referenced key or `NIL', if none is
available.
`CNObject *next_object();'
Moves the iterator to the next element of the hash table. It
returns the object of the current referenced key (the one BEFORE
moving the iterator) or `NIL', if none is available.
`CNObject *prev_object();'
Moves the iterator to the previous element of the hash table. It
returns the current referenced key (the one BEFORE moving the
iterator) or `NIL', if none is available.
The following examples show how to use a `CNHashIterator' object to
traverse an hash table:
Forward:
CNHashDynamic hash_table;
...
CNHashIterator trav(hash_table);
CNKey *key;
CNObject *obj;
while(key = trav++)
{
// Do something with key ...
obj = key->get_object();
}
Alternate forward:
for(trav.reset(hash_table); key = trav.key(); trav.next())
{
// ...
}
Forward with objects:
for(trav.first(); obj = trav.object(); trav.next_object())
{
// ...
}
Backward:
for(trav.last(); key = trav.key(); trav--)
{
// ...
}
The only way to delete all entries of an hash table, that is guaranteed
to work with `CNHashIterator':
for(trav.reset(hash_table); key = trav.key(); trav.reset())
{
// delete object associated with key
delete key->get_object();
// delete hash table entry and key
hash_table->delete_key_absolutely(key);
}
File: cncl.info, Node: CNManager, Next: CNPipe, Prev: CNHashIterator, Up: Object Management
CNManager - Object Management Frontend
======================================
SYNOPSIS
--------
`#include <CNCL/Manager.h>'
TYPE
----
`CN_MANAGER'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
None
RELATED CLASSES
---------------
* CNHashTable:: Abstract Base Class for Hash Tables
* CNHashDynamic:: Hash Tables with Dynamic Capacity
* CNKey:: Abstract Base Class for Object Management via Keys
* CNKeyString:: Object Management via String Keys
* CNKeyInt:: Object Management via Integer Keys
DESCRIPTION
-----------
`CNManager' is a class which provides facilities for storing and
retrieving CNCL compatible objects in a filesystem-like manner.
Objects of type `CN_MANAGER' can be compared with directories, whereas
all other CNCL compatible objects play the role of the files.
`CNManager' internally uses a dynamic hash table for managing the
objects.
Constructors:
`CNManager(char *object_name = NIL);'
`CNManager(CNParam *param);'
Initializes `CNManager'.
Destructor:
`~CNManager();'
Frees all internally allocated resources.
In addition to the member functions required by CNCL, `CNManager'
provides:
`CNObject *new_object(char *object_name, CNClassDesc desc, CNParam *param = NIL);'
`new_object()' is used to create a tree of objects similar to a
filesystem's tree of directories and files. The class descriptor
`desc' determines whether a directory (`CN_MANAGER') or a file
(any other type) is to be created. The `object_name' may consist
of a pathname and/or a basename. All directory-names and the
basename must be separated by slashes ('/'). The pointer to the
new created object is returned, if no error occurs, otherwise, if
e. g. the specified pathname was incorrect, `NIL' is returned.
`bool delete_object(char *object_name);'
Removes the specified object from the internal hashtable. The
memory allocated for the object via `new_object()' is deleted, too.
As described under `new_object()' you may pass a filesystem-like
path to `delete_object()'. If the object is deleted succesfully,
`TRUE' is returned, `FALSE' otherwise. If the object to be deleted
is a 'directory' and if the 'directory' still contains valid
'files', `delete_object()' fails. You must first delete all
subentries before deleting the entry itself.
`CNObject *get_object(char *object_name) const;'
Returns the object associated to the given pathname. If the
specified object does not exist, `NIL' is returned.
`char *get_name();'
Returns the basename of the respective object.
`bool is_empty() const;'
Returns TRUE if no object is stored in the storing facilities of
this class, FALSE otherwise.
The following example shows how to use `CNManager' objects in order
to store and retrieve CNCL compatible objects.
// this is the root of the example's object hierarchy
CNManager root;
// some 'directory' pointers
CNManager *mobile, *base, *subbase;
// some 'file' pointers
CNHashDynamic *table1, *table2;
// create a 'directory' in the root 'directory'
mobile = (CNManager *)root.new_object("mobile", CN_MANAGER);
if (mobile == NIL)
...
// create another 'directory'
base = (CNManager *)root.new_object("base", CN_MANAGER);
if (base == NIL)
...
// now create a 'file' (CNCL compatible object) in the
// 'mobile' 'directory'
table1 = (CNHashDynamic *)mobile->new_object("table1", CN_HASHDYNAMIC);
if (table1 == NIL)
...
// now create a 'subdirectory' of 'base' using an absolute path
subbase = (CNManager *)root.new_object("/base/subbase", CN_MANAGER);
if (subbase == NIL)
...
// create a 'file' using a path relative to 'base'
table2 = (CNHashDynamic *)base->new_object("subbase/table2", CN_HASHDYNAMIC);
if (table2 == NIL);
...
// now try to get an object
if (base->get_object("subbase/table2") == table2)
...
// try to delete 'subbase'
if (!root.delete_object("/base/subbase")) // error, dir not empty
...
// first delete all subentries
if (!root.delete_object("/base/subbase/table2"))
...
// now delete subbase
if (!base->delete_object("subbase")) // okay
...
...
File: cncl.info, Node: Misc, Next: EZD Interface, Prev: Unix, Up: Top
Miscellaneous Classes
*********************
The classes described in this chapter are provided by the CNCL class
library for miscellaneous purposes such as:
`common coordinates for the graphical interface to EZD'
`common string handling (as a CNObject)'
`common integer and double handling (as a CNObject)'
`support of named object management'
`integer2string and double2string conversion'
`reference counting'
* Menu:
* CNCoord:: 2-Dimensional Coordinates
* CNICoord:: 2-Dimensional Integer Coordinates
* CNString:: Character String
* CNNamed:: CNObject with Name
* CNIniFile:: .ini-style config file
* CNFormInt:: Integer as CNStrings
* CNFormFloat:: Doubles as CNStrings
* CNInt:: Integer derived from CNObject
* CNDouble:: Double derived from CNObject
* CNGetOpt:: Interface to GNU getopt()
* CNRef:: Base class for classes with reference counting
* CNRefObj:: CNObject with reference counting
* CNRefNamed:: CNNamed with reference counting
* CNPtr:: Intelligent pointer to CNRefObjs
File: cncl.info, Node: CNCoord, Next: CNICoord, Prev: CNSelect, Up: Misc
CNCoord -- 2-Dimensional Coordinates
====================================
SYNOPSIS
--------
`#include <CNCL/Coord.h>'
TYPE
----
`CN_COORD'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNICoord:: 2-Dimensional Integer Coordinates
DESCRIPTION
-----------
`CNCoord' is a data type for managing 2-dimensional coordinates. It
is typically used together with `CNICoord' for world coordinates and
pixel coordinates respectively.
A `CNCoord' has `double' x and y members which are public accessible.
`CNCoord's can be automatically converted to `CNICoord's and vice
versa. This is done by applying the conversion factor `CNCoord::scale'.
Constructors:
`CNCoord();'
`CNCoord(CNParam *param);'
`CNCoord(double vx, double vy);'
`CNCoord(const CNICoord &v);'
`CNCoord(const CNCoord &v);'
Initializes the coordinates object and optionally sets x and y
components.
Public accessible members:
`double x;'
`double y;'
The x and y components of `CNCoord'.
In addition to the member functions required by CNCL, `CNCoord'
provides:
`CNCoord &operator = (const CNCoord &v);'
`CNCoord &operator += (const CNCoord &v);'
`CNCoord &operator -= (const CNCoord &v);'
Defines the operators `=', `+=' and `-=' for coordinates by
applying the standard C/C++ operators to the x and y components.
The following static member functions are provided to manipulate the
conversion scale setting:
`static double CNCoord::get_scale();'
`static double CNCoord::set_scale(double new_scale);'
Gets/sets the scale setting.
Global operators:
`CNCoord operator + (const CNCoord &a, const CNCoord &b);'
`CNCoord operator - (const CNCoord &a, const CNCoord &b);'
Adds/substracts coordinates by adding/subtracting the x and y
components.
File: cncl.info, Node: CNICoord, Next: CNString, Prev: CNCoord, Up: Misc
CNICoord -- 2-Dimensional Integer Coordinates
=============================================
SYNOPSIS
--------
`#include <CNCL/ICoord.h>'
TYPE
----
`CN_ICOORD'
* Menu:
BASE CLASSES
------------
* CNObject:: Root of the CNCL Hierarchy
DERIVED CLASSES
---------------
RELATED CLASSES
---------------
* CNCoord:: 2-Dimensional Coordinates
DESCRIPTION
-----------
`CNICoord' is a data type for managing 2-dimensional integer
coordinates. It is typically used with `CNCoord' for pixel coordinates
and world coordinates respectively.
A `CNICoord' has `int' x and y members which are public accessible.
`CNICoord's can be automatically converted to `CNCoord's and vice
versa. This is done by applying the conversion factor `CNCoord::scale'.
Constructors:
`CNICoord();'
`CNICoord(CNParam *param);'
`CNICoord(int vx, int vy);'
`CNICoord(const CNCoord &v);'
`CNICoord(const CNICoord &v);'
Initializes the integer coordinates object and optionally sets x
and y components.
Public accessible members:
`int x;'
`int y;'
The x and y components of `CNICoord'.
In addition to the member functions required by CNCL, `CNICoord'
provides:
`CNICoord &operator += (const CNICoord &v);'
`CNICoord &operator -= (const CNICoord &v);'
Defines the operators `+=' and `-=' for integer coordinates,
applying the standard C/C++ operators to the x and y components.
The following static member functions are provided to manipulate the
conversion scale setting:
`static double CNICoord::get_scale();'
`static double CNICoord::set_scale(double new_scale);'
Gets/sets the scale setting.
Global operators:
`CNICoord operator + (const CNICoord &a, const CNICoord &b);'
`CNICoord operator - (const CNICoord &a, const CNICoord &b);'
Adds/substracts integer coordinates by adding/subtracting the x
and y components.